<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../lib/jquery-3.4.1.js"></script>

</head>

<body>
    
    <script>
        var url = "http://douban.uieee.com/v2/movie/top250"
        $.ajax({
                    url,
                    type: "get",
                    dataType: "jsonp",
                    success: res => {
                            console.log(res.subjects);
                            var subjects = res.subjects;
                            var movies = [];
                            for (var i = 0; i < subjects.length; i++) { //将原来的对象里的数据传递一部分给自建立对象。
                                var obj = {};
                                obj.title = subjects[i].title;
                                obj.imageUrl = subjects[i].small;
                                movies.push(obj)
                            }
                            for (var j = 0; j < movies.length; j++) {
                                // var $div=$("<div></div>")
                                // var $img=$("<img />")
                                // var $p=$(`<p>${movies[j].title}</p>`)
                                // $img.attr("src",movies[j].imageUrl)
                                // console.log($img)
                                // $div.append($img)
                                // $("body").append($div)
                                // $p.append($p)
                                var item = $(`<div><img src="${movies[j].imageUrl}/"><p>${movies[j].title}</p></div>`);
                    $("body").append(item)
                }
                console.log(movies);
            },
            error:err=>{
                console.log(err.status);//返回网页状态码
                if(err.status==404){
                    window.location.href="404.html"//当页面无法访问的时候转到这个页面   `
                }
            }
        })
    </script>
</body>

</html>